package com.pan.thread;

import lombok.extern.slf4j.Slf4j;

/**
 * @author by panstark
 * @description
 * @notice
 * @date 2021/4/29
 */
@Slf4j
public class HorseThread extends Thread {


    @Override
    public void run() {
        log.info("主线程在睡觉。");
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        log.info("我是一匹{}，因为我继承了Thread类，这样我就是一个单独的线程在跑。",Thread.currentThread().getName());
    }


    /**
     * 在主线程休眠时，子线程自己执行，不受主线程影响
     * @param args
     */
    public static void main(String[] args) {

        HorseThread horseThread = new HorseThread();
        horseThread.setName("线程千里马");
        horseThread.start();
        horseThread.interrupt();
        try {
            log.info("让主线程:{}睡5秒",Thread.currentThread().getName());
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        log.info("主线程:{}醒了，程序结束了。",Thread.currentThread().getName());
    }

}
